package com.spark.core.transformation

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * union 合并两个RDD
 * union 合并RDD ，两个RDD必须是同种类型，不必要是K,V格式的RDD
 * 结果的RDD的分区数等于合并的两个分区数的和
 * 没有shuffle, 下游的Rdd每个分区对应处理上游的Rdd数据
 */
object Demo12_union {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("union")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")
    val rdd1 = sc.parallelize(List[String]("zhangsan", "lisi", "wangwu", "maliu"), 3)
    val rdd2 = sc.parallelize(List[String]("a", "b", "c", "d"), 4)
    val unionRDD: RDD[String] = rdd1.union(rdd2)
    unionRDD.foreach(println)
    println("unionRDD partitioin length = " + unionRDD.getNumPartitions)


  }
}
